home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c / 657 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  1.7 KB

  1. Path: lyra.csx.cam.ac.uk!jkb
  2. From: jkb@mrc-lmb.cam.ac.uk (James Bonfield)
  3. Newsgroups: comp.std.c
  4. Subject: Re: Restrictions on qsort compare function?
  5. Date: 27 Mar 1996 09:40:00 GMT
  6. Organization: MRC Laboratory of Molecular Biology, Cambridge UK
  7. Message-ID: <4jb2dg$f7d@lyra.csx.cam.ac.uk>
  8. References: <mjs.827419998@hubcap> <mjs.827424727@hubcap> <1996Mar24.071329.24975@sq.com>
  9. NNTP-Posting-Host: alf2.mrc-lmb.cam.ac.uk
  10.  
  11. In article <1996Mar24.071329.24975@sq.com> msb@sq.com (Mark Brader) writes:
  12. >Incidentally, I have encountered code where the comparison function for
  13. >qsort() actually WAS specified with a return expression like *a < *b that
  14. >produced 0 when it should have produced -1.  The interesting part is that,
  15. >on the particular machine the programmer had been using, the sort worked
  16. >correctly.  Evidently this particular qsort() implementation only tested
  17. >whether the comparison function returned a positive value or not.
  18.  
  19. Indeed in our bugged code this was the case for SunOS 4 and SunOS 5. Irix 5.3
  20. also sorted correctly _most_ of the time (and crashed other times). This all
  21. strikes me as somewhat odd. In contrast to this DEC OSF/1 3.0 gave the
  22. expected not-sorted-too-well result. The OSF system also arrived at this
  23. result with far fewer comparisons. It also arrives at the correct result with
  24. far fewer comparisons than other systems when testing them all with a valid
  25. sort comparison function. My guess is that they don't use quicksort (or at
  26. least for small number of itmes) :-) Which, of course, is perfectly compliant.
  27.  
  28.     James
  29. --
  30. James Bonfield (jkb@mrc-lmb.cam.ac.uk)   Tel: 01223 402499   Fax: 01223 412282
  31. Medical Research Council - Laboratory of Molecular Biology,
  32. Hills Road, Cambridge, CB2 2QH, England.
  33.